package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jiyun.mapper.BiaoqianMapper;
import com.jiyun.model.xitong.Biaoqian;
import com.jiyun.service.IBiaoqianService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-21
 */
@Service
public class BiaoqianServiceImpl extends ServiceImpl<BiaoqianMapper, Biaoqian> implements IBiaoqianService {
    @Autowired
    BiaoqianMapper biaoqianMapper;

    @Override
    public Page<Biaoqian> findAll(Integer pageNum, Integer pageSize, Biaoqian biaoqian) {
        Page<Biaoqian> biaoqianPage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Biaoqian> biaoqianLambdaQueryWrapper= new LambdaQueryWrapper<>();
        biaoqianLambdaQueryWrapper.like(StringUtils.isNotBlank(biaoqian.getName()),Biaoqian::getName,biaoqian.getName());
      return   biaoqianMapper.selectPage(biaoqianPage,biaoqianLambdaQueryWrapper);
    }

    @Override
    public Integer add(Biaoqian biaoqian) {
        if (biaoqian.getId()==null){
            Biaoqian biaoqian1= new Biaoqian();
            biaoqian1.setUpdateTime(new Date());
            biaoqian1.setStatus("1");
            biaoqian1.setUserId(1);
            biaoqian1.setName(biaoqian.getName());
            biaoqianMapper.insert(biaoqian1);
        }else {
            biaoqianMapper.updateById(biaoqian);
        }
        return 0;
    }

    @Override
    public Integer del(Integer id) {
        return biaoqianMapper.deleteById(id);
    }

    @Override
    public List<Biaoqian> findBiaoQian() {
        return biaoqianMapper.selectList(null);
    }
}
